/**create by liuhua at 2020年10月22日 下午4:45:09**/
package com.star.aries.utils;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.stream.Stream;

public class FileUtils {
  
  public static void save(String file, String content) throws IOException {
    FileWriter writer = new FileWriter(file);
    writer.write(content);
    writer.flush();
    writer.close();
  }
  
  public static String read(String file) throws IOException {
    FileReader reader = new FileReader(file);
    char[] cbuf = new char[1024];
    StringBuffer buffer = new StringBuffer();
    while(reader.read(cbuf) != -1) {
      buffer.append(new String(cbuf, 0, cbuf.length));
    }
    reader.close();
    return buffer.toString();
  }
  
  public static boolean allExists(String ... filepath) {
    if(null == filepath || filepath.length == 0) {
      return false;
    }
    return Stream.of(filepath).allMatch(path -> new File(path).exists());
  }
}
